package br.com.sms.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;

public class UtilArquivo implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		
	public File criarArquivo(InputStream in, String destino, String fileName){

		File file = null;
		
		try {
			BufferedInputStream bufferIn = new BufferedInputStream(in);

			file = new File(destino);
			if(!file.exists()){
				file.mkdir();
			}
			file = new File(destino + fileName);
			file.createNewFile();

			OutputStream bos = new FileOutputStream(file);

			
			int teste = 0;
			while ((teste = bufferIn.read()) != -1) {
				bos.write(teste);
			}

			in.close();
			bufferIn.close();
			bos.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		return file;

	}
	
}
